import { Empty, Image } from 'antd';
import forbiddenImageData from '../data/forbiddenImageData';

const hasAuthority = (store: any, role: string) => {
  let flag: boolean = false;
  if (!store?.currentUser?.userData || !store?.currentUser?.userData?.id) {
    flag = true;
  } else if (!store?.currentUser?.hasRole(role)) {
    flag = true;
  }
  if (!flag) {
    return null;
  }
  if (flag && store?.currentUser?.userData?.id === '') {
    return <></>;
  }
  return (
    <Empty
      image={
        <Image
          alt="forbidden"
          src={forbiddenImageData}
          preview={false}
          style={{
            width: 92,
            height: 92
          }}
        />
      }
      description="无权限访问当前页面"
      style={{
        color: 'rgba(0, 0, 0, 0.3)',
        marginTop: 50
      }}
    />
  );
};

export default hasAuthority;
